//涉及到字符串次数统计，模拟hash比set更高效
//循环中有continue的尽量用for不然容易死循环

class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int n=s.length(),m=p.length();
        vector<int> ret;
        if(n<m) return ret;
        array<int, 26> hash1{};
        array<int, 26> hash2{};
        for(auto c:p)
        {
            hash2[c-'a']++;
        }

        
        for(int right=0;right<n;right++)
        {
            hash1[s[right]-'a']++;
            int left=right-p.length()+1;
            if(left<0)continue;

            if(hash1==hash2)ret.push_back(left);
            hash1[s[left]-'a']--;
        }

        return ret;
    }
};